/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package espe.ccsoft.controllers;

import espe.ccsoft.dao.AccionDao;
import espe.ccsoft.models.Accion;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.servlet.http.HttpSession;

@ManagedBean
@RequestScoped
public class AccionController {

    private Accion accion;
    private AccionDao acciondao;
    private List<Integer> id_acciones;

    public AccionDao getAccionDao() {
        acciondao = new AccionDao();
        return acciondao;
    }

    public List<Accion> getAccionByIdPermiso(final int id_permiso) throws Exception {
        return getAccionDao().findByPermisoId(id_permiso);
    }

    public List<Accion> getAccionByIdPermisoIdRol(final int id_rol, final int id_permiso) throws Exception {
        return getAccionDao().findAllByPermisoRol(id_rol, id_permiso);
    }

    @ViewScoped
    public Boolean getAccionByVista(String controlador, String accion) throws Exception {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        int id_rol = (Integer) session.getAttribute("Id_Rol");
        return getAccionDao().findAccesoVista(controlador, accion, id_rol) != null;
    }

    public String getAccionNombreById(final int id) throws Exception {
        return getAccionDao().findNombreById(id);
    }

    public List<Accion> getAllAcciones() throws Exception {
        return getAccionDao().findAll();
    }

    public List<Integer> getId_acciones() {
        return id_acciones;
    }

    public void setId_acciones(List<Integer> id_acciones) {
        this.id_acciones = id_acciones;
    }
}
